package com.zhenwei.zscm.controller;

import com.zhenwei.zscm.common.annotations.Delete;
import com.zhenwei.zscm.common.annotations.Insert;
import com.zhenwei.zscm.common.annotations.MethodName;
import com.zhenwei.zscm.common.annotations.Update;
import com.zhenwei.zscm.common.base.RestResult;
import com.zhenwei.zscm.model.vo.dict.DictVO;
import com.zhenwei.zscm.model.vo.dict.QueryDictVO;
import com.zhenwei.zscm.service.DictService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/dict")
@AllArgsConstructor
@MethodName("字典管理")
public class DictController {
    private DictService dictService;

    @MethodName("获取字典")
    @GetMapping("/list")
    public RestResult list(@RequestParam @NotEmpty(message = "字典类型不能为空") String dictType) {
        return dictService.getList(dictType);
    }

    @MethodName("获取字典列表")
    @PostMapping("/page")
    public RestResult pge(@RequestBody @Valid QueryDictVO query) {
        return dictService.page(query);
    }
    @MethodName("添加字典")
    @PostMapping("/create")
    public RestResult create(@RequestBody @Validated(Insert.class) DictVO dict) {
        return dictService.addDict(dict);
    }

    @MethodName("修改字典名称")
    @PostMapping("/update")
    public RestResult update(@RequestBody @Validated(Update.class) DictVO vo){
        return dictService.updateDict(vo);
    }

    @MethodName("删除字典")
    @PostMapping("/delete")
    public RestResult delete(@RequestBody @Validated(Delete.class) DictVO vo) {
        return dictService.delete(vo);
    }

    @MethodName("获取字典类别")
    @GetMapping("/type")
    public RestResult getDictType() {
        return dictService.getDictType();
    }
}
